<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="<%=basePath%>Js/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mycss/bootstrap.min.css" />
</head>

<script type="text/javascript">

function deleteRoom(roomNumber){
	
	$.ajax({
		type:"post",
		url:"deleteRoom.do",
			data : {
				"roomNumber" : roomNumber,
			},
			dataType : "text",
			success : function(result) {
				if (result == "1") {
					alert("删除房间成功")
					$("#"+roomNumber+"").remove();
				} else {
					alert("删除房间失败")
				}
			},
			error : function() {
				alert("系统故障")
			}

		})	
}

//添加房间
function addRoom(){
	
	var roomNumber = $("#roomNumber").val();
	var floor = $("#floor").find("option:selected").text();
	var roomtype = $("#roomtype").find("option:selected").text();
	if(roomNumber == "" ){
		alert("请输入房间号")
	}else if(!(/(^[0-9]*[1-9][0-9]*$)/.test(roomNumber))){
		alert("你输入的房间号带有字符")
	}else{
		$.ajax({
			type:"post",
			url:"addRoom.do",
			data:{
				"roomNumber":roomNumber,
				"floor":floor,
				"roomtype":roomtype,
			},
			dataType:"text",
			success:function(result){
				
				if(result == "1"){
					alert("添加房间成功")
					window.location.href="";
				}else if(result == "2"){
					alert("房间已存在")
				}else{
					alert("添加失败")
				}
				
			},
			error:function(){
				alert("系统故障")
			}
		})
	}
	
	
}


</script>

<body>
	
	<div style="border-width: 10px;border-color: beige;border-style: double;
		border-radius: -webkit-calc(background-color: );padding: 10px;margin:20px;left: 200px; top: 100px; width: 1100px;height: 1500px">
<hr><h4 align="center" style="color: #4981F8;" align="center">房间管理</h4><hr><br><br>
		<table >
			<tr>
				<td>选择楼层：</td>
				<td><select name="floor" id="floor" class="form-control">

						<c:forEach items="${floorlist}" var="floorlist">

							<option value="1">${floorlist.floor}</option>
						</c:forEach>

				</select></td>
		
				<td>选择房型：</td>
				<td><select name="floor" id="roomtype" class="form-control">

						<c:forEach items="${houselist}" var="typelist">

							<option value="1">${typelist.housetype}</option>
						</c:forEach>

				</select></td>
			</tr>

		</table><br>
		
		<h5>添加房间</h5>
		<table>
		<tr>
		<td><input type="text" class="form-control" id="roomNumber" placeholder="请输入楼层"></td>
		<td><button type="button" class="btn btn-success" onclick="addRoom()">添加</button></td>
		</tr>
		</table>


		<div
			style="position: absolute; left: 500px; top: 150px; width: 500px; height: 10px">
			
			<h3 align="center">房间一览表</h3>

			<br>
<c:forEach items="${floorlist}" var="floorlist">
<div><h5>${floorlist.floor}</h5></div>
			<table class="table table-bordered">
				<tr>
					<th>房间号</th>
					<th>房型</th>
					<th>楼层</th>
					<th>价格</th>
					<th>容纳人数</th>
					<th>操作</th>
				</tr>
				
				<c:forEach items="${pageInfo}" var="roomlist">
				<c:if test="${roomlist.floor == floorlist.floor}">
				<tr id="${roomlist.roomnum}">
					<td>${roomlist.roomnum}</td>
					<td>${roomlist.type}</td>
					<td>${roomlist.floor}</td>
					<td>${roomlist.price}</td>
					<td>${roomlist.quantity}</td>
					<td><a href="#" onclick="deleteRoom('${roomlist.roomnum}')">删除</a></td>
					
				</tr>
				</c:if>
				</c:forEach>
			</table>
			</c:forEach>
			

		</div>

	</div>
	
	
</body>
</html>